<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <base href="<%=request.getContextPath()%>/"/>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@include file="../layUI.jsp" %>
</head>
<body>
<c:choose>
    <c:when test="${not empty pageData}">
        <table width="100%" style="text-align: center" class="layui-table">
            <tr>
                <th>ID</th>
                <th>姓名</th>
                <th>登录账号</th>
                <th>性别</th>
                <th>生日</th>
                <th>证件号</th>
                <th>Email</th>
                <th>电话</th>
                <th>地址</th>
                <th colspan="2">操作</th>
            </tr>
            <tbody id="thebody">

            </tbody>
            <tr>
                <td colspan="10">
                    <%@include file="Page.jsp" %>
                </td>
            </tr>
        </table>
    </c:when>
    <c:otherwise>
        <h3>没有商家</h3>
    </c:otherwise>
</c:choose>
<script src="/js/jquery-2.1.0.js"></script>
<script type="text/javascript">
    var pageCurrentNo = 1;
    var pageSize = 3;
    var totalPage = 0;
    $(function () {
        searchSellers(1)
        $("#begin").click(function () {
            pageCurrentNo = 1;
            searchSellers(pageCurrentNo);
        });
        $("#prev").click(function () {
            pageCurrentNo -= 1;
            searchSellers(pageCurrentNo);
        });
        $("#next").click(function () {
            pageCurrentNo += 1;
            searchSellers(pageCurrentNo);
        });
        $("#end").click(function () {
            pageCurrentNo = $("#totalPages").html();
            searchSellers(pageCurrentNo);
        });
    });

    function searchSellers(pageNo) {
        pageCurrentNo = pageNo;
        $("#thebody").html("");
        $.getJSON("/doSel", {"action": "paging", "pageNo": pageNo}, callback);

        function callback(result) {
            for (var i = 0; i < result.lists.length; i++) {
                $("#thebody").append(
                    "<tr><td>" + result.lists[i].id + "</td>" +
                    "<td>" + result.lists[i].sellerName + "</td>" +
                    "<td>" + result.lists[i].sellerUser + "</td>" +
                    "<td>" + result.lists[i].sellerSex + "</td>" +
                    "<td>" + result.lists[i].sellerBirthday + "</td>" +
                    "<td>" + result.lists[i].sellerIdCard + "</td>" +
                    "<td>" + result.lists[i].sellerEmail + "</td>" +
                    "<td>" + result.lists[i].sellerTel + "</td>" +
                    "<td>" + result.lists[i].sellerAddress + "</td>" +
                    "<td><a class='layui-btn' href='doSel?action=selQueryById&id=" + result.lists[i].id + "'>修改</a></td>" +
                    "<td><a class='layui-btn' href='doSel?action=selDelById&id=" + result.lists[i].id + "'>删除</a></td></tr>"
                )
            }
            $("#pageNo").html(pageCurrentNo);
            $("#totalPages").html(result.totalPage);
            showhide(pageCurrentNo, result.totalPage);
        }
    }

    function showhide(currentPage, totalPages) {
        if (currentPage == 1) {
            $("#prev").hide();
            $("#next").show();
        }
        if (currentPage > 1 && currentPage < totalPages) {
            $("#prev").show();
            $("#next").show();
        }
        if (currentPage == totalPages) {
            $("#prev").show();
            $("#next").hide();
        }
        if (totalPages == 1) {
            $("#prev").hide();
            $("#next").hide();
        }
    }
</script>
</body>
</html>
